<?php
namespace app\admin\controller;



use think\Db;
use think\facade\Request;
use think\facade\View;

class Good
{
    public function good()
    {
        $keywords = Request::get('keywords','','trim,htmlspecialchars,strip_tags');
        $recommended = Request::get('recommended','2','trim,htmlspecialchars,strip_tags');
        $recom = Request::get('recom','2','trim,htmlspecialchars,strip_tags');
        //拼接SQL语句用于查询
        $db = \think\facade\Db::table('ecm_goods')->field(true)->limit(5);

            if ($recommended==2){
                $db->select()->toArray();
            }else{
                $db->where('recommended','=',$recommended);
            }
            if ($recom==2){
                $db->select()->toArray();
            }else{
                $db->where('recom','=',$recom);
            }
            if (''!==$keywords){
                $db->whereLike('goods_name','%'.$keywords.'%');
            }
        echo "<pre>";
        print_r($recom);
        echo "</pre>";
       //向视图层赋值
        View::assign('keywords',$keywords);
        View::assign('recom',$recom);
        View::assign('recommended',$recommended);
        //拼接SQL语句用于查询
        $list= $db->select()->toArray();
        $empty = "<tr><td align='conter' colspan='7'>没有数据</td></tr>";
        View::assign('empty ',$empty);
        View::assign('list',$list);
        return View::fetch();
    }
}